<!--组件-现货运行列表-->
<template>
  <div>
    <div class="bg bg2 bk1" v-if="isShow">
      <LImage class="texture3" :src="Config.img('texture3.png')"></LImage>

      <!--基础信息-->
      <div class="base">

        <div class="column">

          <div class="row aend">
            <text class="font32 text1">{{item.projectName}}</text>

            <div class="row acenter"  v-if="item.errorInfo" @click="msgClick(item)">
              <LImage class='msg' :src="Config.img('baocuo.png')"></LImage>
              <text class="font24 udRed-t1">{{T('信息')}}</text>
            </div>
          </div>

          <div class="height14"></div>
          <text class="font20 text3">{{amRun.getParseTime(item.startTime) + '（' + getExecuteTime(item.startTime, item.endTime) + '）'}}</text>
        </div>
        
        <div class="all"></div>
        <text :class="['font28',  (item.states == 'EXECUTE' ? 'main-t1' : 'text3')]">{{getRunState(item)}}</text>
      </div>
      
      <!--交易所名称-->
      <div class="line bg3"></div>
      <text class="font24 text2">{{getExchangeName(item)}}</text>

      <!--运行信息-->
      <div class="height20"></div>
      <div class="run">

        <div class="run-left">
          <text class="font24 text3">{{T('总投入')+'('+item.investCoin+')'}}</text>
          <div class="height8"></div>
          <text class="font24 text1">{{item.investCoinNum}}</text>
        </div>

        <div class="run-left">
          <text class="font24 text3 ">{{T('总收益')+'('+item.investCoin+')'}}</text>
          <div class="height8"></div>
          <div class="row aend">
            <text :class="['font24', Config.upDownFont(item.realEarnings)]">{{getAddStr(item.realEarnings)}}</text>
            <text :class="['font20', Config.upDownFont(item.realEarnings)]">{{'('+getAddStr(item.realEarningRate)+'%)'}}</text>
          </div>
        </div>

        <div class="run-right">
          <text class="font24 text3">{{T('总年化')}}</text>
          <div class="height8"></div>
          <text :class="['font24', Config.upDownFont(item.realYearIncome)]">{{getAddStr(item.realYearIncome)+'%'}}</text>
        </div>
      </div>

      <!--按钮-->
      <div class="but">
        <div class="all"></div>
        <div class="row acenter" v-if="item.operateStatus == 'moving'">
          <LImage class="time-image" :src="Config.img('bushu_time.png')"></LImage>
          <text class="font30 main-t1">{{T('策略迁移中...')}}</text>
        </div>
        <div class="row acenter" v-else>
          <div class="but-row" @click="stopClick(item, index)"><text class="font24 main-t1">{{T('终止')}}</text></div>
          <div class="but-row" @click="shareClick(item)"><text class="font24 main-t1">{{T('分享')}}</text></div>
          <div class="but-row" @click="detailClick(item)"><text class="font24 main-t1">{{T('详情')}}</text></div>
        </div>
      </div>
    </div> 
  </div>
</template>
    
<script>

import math from "@/_js/math";
import modal from "@/_js/modal";
import Config from "@/_js/config";
import broadcast from "@/_js/broadcast";
import navigator from "@/_js/navigator";

import amRun from "@/run/amRun";
import amRunTrust from "@/run/amRunTrust";

const weexFunction = weex.requireModule("WeexFunction");

import I18N from "@/_i18n/i18n";
var T = I18N.t;

export default {

  props: {
    item: Object, 
  },

  data() {
    return {
      T: T,
      Config: Config,
      amRun: amRun,
      isShow:false,
    };
  },

  mounted() {

    Config.init(()=>{
      this.isShow = true
    },[Config.OPT_UP_DOWN]);
  },

  methods: {
    /*********************** 获取数据*/
    //获取运行状态
    getRunState(item) {
      var state = amRun.getRunState(false, false, item.states);
      //量化托管特殊，需要半个小时候才结算，所以修改文案
      if (state == '正在终止') {
        state = '正在结算';
      }
      return T(state);
    },

    //获取运行时间长
    getExecuteTime(startTime, endTime){
      var time = amRun.getRunTime(startTime, endTime, T('天'), T('时'), T('分'));
      return time;
    },

    /********************************** Get方法*/
    //获取+字符串
    getAddStr(value) {
      value = math.xiaoShuDelete0(value);
      value = math.addJia(value);
      return value;
    },

    //获交易所名称
    getExchangeName(item){
      var remark = item.remark && item.remark.length ? ('·' + item.remark) : '';
      return item.apiName + remark + '（' + T('量化托管') + '）';
    },
    /********************************** 点击触发*/
    //终止点击
    stopClick(item){

      if (item.states == "STOPING" ) {
        modal.toast(T('请勿频繁操作'));
        return;
      }
      
      navigator.openDialog('run/RunStopTrust');
      broadcast.subscribeOnce('RunStopTrust', ()=>{

        var param = {'executeId':item.executeId};
        amRunTrust.httpEnd(param,()=>{
          broadcast.send(broadcast.EXECUTE_UPDATE);
        });
      });
    },

    //消息点击
    msgClick(item){

      item.errorInfo = false;
      navigator.open(T('策略消息'), 'strategy/StrategyNotice', {'stId':item.executeId});
    },

    //分享点击
    shareClick(item){

      var tiem = this.getExecuteTime(item.startTime, item.endTime);
      var param = {'teamName':item.teamName,
                  'projectName':item.projectName,
                  'investCoin':item.investCoin,
                  'realEarningRate':item.realEarningRate,
                  'realYearIncome':item.realYearIncome,
                  'time':tiem};
      weexFunction.shareWeex('share/ShareRunTrust',{'param':param});
    },

    //详情点击
    detailClick(item){

      if (item.states == "STARTING" ) {
        modal.toast(T('启动中，无法查看详情！'));
        return;
      }

      var param = {'executeId':item.executeId};
      navigator.open('','run/RunInfot',param);
    },
  },
};
</script>


<style src="@/_css/style.css"></style>
<style scoped>
.bg {
  border-width: 1px;
  border-radius: 8px;

  padding-top: 40px;
  padding-left: 40px;
  padding-right: 40px;
  padding-bottom: 40px;

  margin-bottom: 20px;
}
.line {
  height: 1px;
  margin-top: 20px;
  margin-bottom: 20px;
}

/*********************** 服务器标题*/
.server-tag {
  position: absolute;
  flex-direction: row;
  align-items: center;
  height: 32px;

  border-bottom-left-radius: 8px;
  border-top-right-radius: 8px;

  padding-left: 14px;
  padding-right: 14px;

  top: 0;
  right: 0;
}

/*********************** 基础信息*/
.base {
  flex-direction: row;
  align-items: center;
}

/*********************** 投入信息*/
.invest {
  flex-direction: column;
  justify-content: space-between;
}

/*********************** 运行信息*/
.run {
  flex-direction: row;
  justify-content: space-between;
}
.run-left{
  flex-direction: column;
}
.run-right {
  flex-direction: column;
  align-items: flex-end;
}

/*********************** 操作按钮*/
.but{
  flex-direction: row;

  margin-top: 40px;
  margin-left: -40px;
  margin-right: -20px;
}
.but-row{
  flex-direction: row;
  align-items: center;
  padding-left: 20px;
  padding-right: 20px;
}
.time-image {
  width: 30px;
  height: 30px;
  margin-right: 10px;
}

/*********************** 类型标签*/
.tag{
  flex-direction: row;
  align-items: center;
  height: 64px;
  padding-left: 40px;
  padding-right: 50px;
  border-top-right-radius: 32px;
  border-bottom-right-radius: 32px;
}

/*********************** 间距*/
.height8{
  height: 8px;
}
.height14 {
  height: 14px;
}
.height20{
  height: 20px;
}
</style>